<template>
  <div class="servegroup">
    <ConTitle :info="info"></ConTitle>
    <!-- <el-form ref="form" :model="query" :inline="true" label-width="100px">
    </el-form> -->
    <el-table :data="accountlist" style="width: 100%">
      <el-table-column prop="account" label="账号" width="180">
      </el-table-column>
      <el-table-column prop="username" label="用户名称" width="180">
      </el-table-column>
      <el-table-column prop="type" label="类型" width="180"> </el-table-column>
      <el-table-column prop="cTime" label="创建时间" width="180">
        <template slot-scope="scope">
          {{ scope.row.cTime | cTimeType }}
        </template>
      </el-table-column>
      <el-table-column prop="uTime" label="更新时间" width="180">
        <template slot-scope="scope">
          {{ scope.row.uTime | uTimeType }}
        </template>
      </el-table-column>
      <el-table-column prop="desc" label="描述" width="180"> </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button
            type="primary"
            icon="el-icon-edit"
            circle
            @click="editFun(scope.row)"
          ></el-button>
          <el-button
            type="danger"
            icon="el-icon-delete"
            circle
            @click="delFun(scope.row)"
          ></el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import ConTitle from "@/components/ConTitle.vue";
import moment from "moment";
import { $accountlist, $accountDel } from "@/api/index";
export default {
  name: "AccountlistView",
  data() {
    return {
      info: {
        path: "计费/",
        text: "充值记录",
        msg: "展示当前账户得消息额度得所有充值记录。",
      },
      accountlist: [],
    };
  },
  components: {
    ConTitle,
  },
  filters: {
    cTimeType(value) {
      return moment(value).format("LL");
    },
    uTimeType(value) {
      return moment(value).format("LL");
    },
  },
  mounted() {
    // 调用第一页数据
    this.getListData();
  },
  methods: {
    getListData() {
      $accountlist().then((res) => {
        console.log(res);
        this.accountlist = res.data.data;
      });
    },
    editFun(row) {
      // 页面跳转并传参
      this.$router.push({ path: "/account/addaccount", query: row });
    },
    delFun(row) {
      console.log(row);
      this.$confirm("此操作将永久删除该条记录, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          $accountDel({ id: row.id }).then((res) => {
            if (res.data.msg == "success") {
              this.$message({
                type: "success",
                message: "删除成功!",
              });
              this.getListData();
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
  },
};
</script>


<style lang="scss" scoped>
.gateway {
  padding: 10px;
}
.search-end {
  font-size: 12px;
  margin-left: 40px;
  color: #858793;
}
.el-input {
  width: 220px;
}
.el-form {
  display: flex;
  margin-top: 20px;
}
.addbtn {
  width: 100px;
  height: 35px;
}
</style>